package com.yuw.collectiontool;

/**
 * Student类实现Comparable接口之后，Student类就具有了比较的行为能力
 */
public class Student implements Comparable<Student> {
    // 属性
    private String stuName;
    private String stuNum;
    private int stuScore;

    // 行为
    // 构造方法
    public Student(String stuName, String stuNum, int stuScore) {
        this.stuName = stuName;
        this.stuNum = stuNum;
        this.stuScore = stuScore;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public String getStuNum() {
        return stuNum;
    }

    public void setStuNum(String stuNum) {
        this.stuNum = stuNum;
    }

    public int getStuScore() {
        return stuScore;
    }

    public void setStuScore(int stuScore) {
        this.stuScore = stuScore;
    }


    /**
     * 打印学生信息
     */
    public void printMe() {
        System.out.println(this.toString());
    }

    // 重写toString方法

    @Override
    public String toString() {
        return "Student{" +
                "stuName='" + stuName + '\'' +
                ", stuNum='" + stuNum + '\'' +
                ", stuScore=" + stuScore +
                '}';
    }

    @Override
    public int compareTo(Student stu) {
        // 设置返回flag 默认值是0，相等；当然，默认值可以根据业务来定，不是一定要初始化为0
        int flag = 0;
        // 通过成绩高低确定排序标准
        if (stu != null) {
            // 大于
            if (this.getStuScore() > stu.getStuScore()) {
                flag = 1;
            }
            // 小于
            if (this.getStuScore() < stu.getStuScore()) {
                flag = -1;
            }
        }
        return flag;
    }
}
